package com.zjw.controller;

import com.zjw.entity.User;
import com.zjw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:0xOO
 * @Date: 2018/9/26 0026
 * @Time: 14:42
 */

@RestController
@RequestMapping("/testBoot")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/getUser/{id}")
    public String getUser(@PathVariable int id){
        return userService.Sel(id).toString();
    }

    @PostMapping("/update")
    public int modifyUser(@RequestBody User user) throws Exception {

        return userService.selectAndUpdate(user);
    }

    @PostMapping("/add")
    public User addUser(@RequestBody User user) throws Exception {

        return userService.add(user);
    }

    @PostMapping("/query.do")
    public User query(@RequestParam int id){

        return userService.getOne(id);
    }

    @PostMapping("/get.do")
    public List<User> getUser(){

        return userService.getAll();
    }

    @PostMapping("/delete.do")
    public int delete(@RequestParam int id){

        return userService.delete(id);
    }

}
